﻿using System;
using System.Web.UI.WebControls;

namespace Lswweb.Domain
{
    public class Enum<T>
    { 

        public static void BinderToListControl(ListControl listControl)
        {
            BinderToListControl(listControl,null);
        }
        public static void BinderToListControl(ListControl listControl,params T[] noBinderItem)
        {
            listControl.Items.Clear();
            Type type = typeof(T);
            Array values = Enum.GetValues(type);
            foreach (T t in values)
            {
                if (noBinderItem != null)
                {
                    bool label = false;
                    foreach (T noT in noBinderItem)
                    {
                        if (t.Equals(noT))
                        {
                            label = true;
                            continue;
                        }
                    }
                    if (label)
                        continue;
                }

                ListItem item = new ListItem(GetEnumStr(t), (Convert.ToInt32(t)).ToString());
                listControl.Items.Add(item);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static string GetEnumStr(T t)
        {
            if (t == null)
                return string.Empty;

            string name = t.GetType().Name;

            return ResourceManagement.Content.Strings[string.Format("{0}_{1}", name, t.ToString())];
        }
    }
}
